#include "ControlCenter.h"
#include <stdio.h>

#include "world/RobotsFactory.h"

ControlCenter::ControlCenter()
    : _radar(new Radar())
    , _factory(new RobotsFactory())
{
    _radar->setViewMode(RADARMODE_WITHOUT_HOSTILE);
}

Researcher &ControlCenter::createResearcher()
{
    auto ret = _factory->createResearcher();
    registerRobot(IRobotPtr(ret));
    return *ret;
}

Worker &ControlCenter::createWorker()
{
    auto ret = _factory->createWorker();
    registerRobot(IRobotPtr(ret));
    return *ret;
}

Warrior &ControlCenter::createWarrior()
{
    auto ret = _factory->createWarrior();
    registerRobot(IRobotPtr(ret));
    return *ret;
}

void ControlCenter::printRobotsData()
{
    // TODO: print additional information
    for (auto it = _robotsOnBase.begin(); it != _robotsOnBase.end(); ++it)
    {
        IRobot &ref = **it;
        ref.sayMyName();
        if (ref.hasWings())
            puts("Robot has wings");
        else
            puts("Robot has no wings");
    }
}

std::vector<IRobot *> &ControlCenter::getRobots()
{
    return _radar->getRobots();
}

void ControlCenter::registerRobot(const IRobotPtr &ptr)
{
    _robotsOnBase.insert(ptr);
    theWorld().registerRobot(ptr);
}
